UNPKG

@damourlabs/euro-clinical-trials

Version:

A Nuxt 3 application for visualizing and managing clinical trials data in Europe, built with modern web technologies.

47 lines (37 loc) 1.25 kB
import { protocolsSchema, type Protocol } from "~/server/database/schema" import type { ServerResponse } from "~/models/utils" import { useDb } from "~/server/utils/drizzle"; export default defineEventHandler(async (event) => { // Protocol creation doesn't need an ID parameter since UUID is auto-generated const { success, error, data } = await readValidatedBody(event, protocolsSchema.safeParse) if (!success) { console.error('Invalid protocol data:', error); throw createError({ statusCode: 400, statusMessage: 'Invalid protocol data', data: error }) } if (!data) { throw createError({ statusCode: 400, statusMessage: 'Protocol data is required' }) } console.log('Creating protocol with data:', data) // Save the new protocol to storage await useDb().insert(tables.protocols).values( { ...data } ) // Return the created protocol const response: ServerResponse<Protocol> = { status: 'success', statusCode: 201, statusText: 'Created', message: 'Protocol created successfully', data: data as Protocol } return response })